package com.telephone.purchase.controller;

import com.telephone.purchase.service.IndexService;
import com.telephone.purchase.util.Result;
import org.hibernate.validator.constraints.EAN;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/indexDate")
public class IndexController {

    @Autowired
    IndexService indexService;

    @RequestMapping(value = "/unifiedInformation",method = RequestMethod.GET)
    public Result unifiedInformation(){
        try {
            Map<String,String> map =indexService.getUnifiedInformation();
            if(map!=null){
                System.out.println(map);
                return Result.success(map);
            }else {
                return Result.fail("9001","获取数据发生异常");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("9001","获取数据发生异常");
        }
    }
    @RequestMapping(value = "/polyLineData",method = RequestMethod.GET)
    public Result polyLineData(){
        try {
            Map<String,List> map =indexService.getPolyLineData();
            if(map!=null){
                System.out.println(map);
                return Result.success(map);
            }else {
                return Result.fail("9001","获取数据发生异常");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("9001","获取数据发生异常");
        }
    }
    @RequestMapping("/pieGraphData")
    public Result pieGraphData(){
        try {
            List<Map> list=indexService.getPieGraphData();
            if(list!=null){
                System.out.println(list);
                return Result.success(list);
            }else {
                return Result.fail("9001","获取数据发生异常");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Result.fail("9001","获取数据发生异常");
        }
    }
}